package org.wms.minbearwcs.serivce.inbound;


import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.wms.minbearwcs.dao.inbound.inf.InboundOrderDao;
import org.wms.minbearwcs.dao.inbound.inf.InboundOrderDetailDao;
import org.wms.minbearwcs.dao.stock.inf.MaterialStockDao;
import org.wms.minbearwcs.entity.DTO.inbound.mission.CallAgvToExchangeArea;
import org.wms.minbearwcs.entity.DTO.inbound.pda.InboundPdaCallAgv;
import org.wms.minbearwcs.entity.DTO.transfer.Tuple;
import org.wms.minbearwcs.entity.PO.wcs.inbound.InboundOrderDetail;
import org.wms.minbearwcs.entity.PO.wcs.inbound.status.InboundOrderDetailStatus;
import org.wms.minbearwcs.serivce.mission.generate.MissionGeneratorCollector;
import org.wms.minbearwcs.serivce.mission.generate.type.MissionGenType;

@Service
@RequiredArgsConstructor
public class InboundPdaService {


    private final InboundOrderDao inboundOrderDao;
    private final InboundOrderDetailDao inboundOrderDetailDao;
    private final MissionGeneratorCollector missionGeneratorCollector;

    public Tuple<String> receiveCallAgv(InboundPdaCallAgv inboundPdaCallAgv) {
        InboundOrderDetail inboundOrderDetail = inboundOrderDetailDao.selectDetailByOrderCodeAndPalletCode(
                inboundPdaCallAgv.getPalletCode(),
                InboundOrderDetailStatus.WAIT_FOR_CALL_AGV
        );

        if (inboundOrderDetail == null) {
            return Tuple.tuple("任务已开始或者不存在",false);
        }

        inboundOrderDetailDao.updateStartPointById(inboundOrderDetail.getId(), inboundPdaCallAgv.getStartPoint());

        CallAgvToExchangeArea callAgvToExchangeArea = new CallAgvToExchangeArea(inboundOrderDetail.getInboundOrderCode(),
                inboundPdaCallAgv.getPalletCode(),
                inboundPdaCallAgv.getStartPoint(),
                1,
                inboundOrderDetail.getId());
        return missionGeneratorCollector.getGenerator(MissionGenType.INBOUND).generate(callAgvToExchangeArea);

    }
}
